﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExBlogger.Domain.Strategy;
using SharpArch.Domain.DomainModel;

namespace ExBlogger.Domain {
    public class User : Entity {

        protected internal User() {
            Username = String.Empty;
            Password = String.Empty;
            CreationDate = DateTime.Now;
            Blogs = new List<Blog>();
        }

        public virtual string Username { get; protected internal set; }
        public virtual string Password { get; protected internal set; }
        public virtual DateTime CreationDate { get; protected internal set; }
        public virtual bool IsApproved { get; protected internal set; }
        public virtual IList<Blog> Blogs { get; protected internal set; }

        public virtual Blog CreateBlog(string head, string subhead) {
            var strategy = new UserStrategy(this);
            if (!strategy.CanCreateBlog)
                return null;

            Blog blog = new Blog();
            blog.Head = head;
            blog.Subhead = subhead;
            blog.CreationDate = DateTime.Now;
            blog.Owner = this;
            return blog;
        }

        public virtual Post CreatePost(string title, string content) {
            if (!new UserStrategy(this).CanPostOnBlog)
                return null;
            Post post = new Post();
            post.Title = title;
            post.Content = content;
            post.PostedBy = this;
            return post;
        }

        public virtual Comment CreateComment(string content) {
            Comment comment = new Comment();
            comment.Content = content;
            comment.CommentedBy = this;
            return comment;
        }
    }
}
